package com.qctpos.crm.common.result;

import com.qctpos.crm.common.contants.ResultCode;
import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T>  implements Serializable {
    private static final long serialVersionUID = 1L;

    private Integer code;

    private String message;

    private Object data;


    public static Result success(){
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(ResultCode.SUCCESS.getMessage());
        return result;
    }

    public static<T> Result<T> success(T data){
        Result result = new Result<T>();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(ResultCode.SUCCESS.getMessage());
        result.setData(data);
        return result;
    }

    public static<T> Result<T> success(String message, T data){
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(message);
        result.setData(data);
        return result;
    }
    public static Result failure(ResultCode resultCode){
        Result result = new Result();
        result.setCode(resultCode.getCode());
        result.setMessage(resultCode.getMessage());
        return result;
    }

    public static Result failure(ResultCode resultCode, String message){
        Result result = new Result();
        result.setCode(resultCode.getCode());
        result.setMessage(message);
        return result;
    }

    public static<T> Result<T> Instance(ResultCode resultCode, String message,T data){
        Result result = new Result();
        result.setCode(resultCode.getCode());
        result.setMessage(message);
        result.setData(data);
        return result;
    }

}
